package de.tabuma.ssoclient.logik;

import java.util.*;
import de.tabuma.lib.webservice.client.*;
import de.tabuma.ssoclient.entity.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.2.4.1 $
 * @since $Date: 2010/01/13 10:23:24 $
 */
public class CustomerFacade {
    public static String soapUrl = "https://tabumasso.appspot.com/webservice";
    public static int create(Customer customer, String ssoId) throws Exception {
        String methodName = "CustomerService_create";
        String soapAction = "CustomerService_create";

        Class returnType = Integer.class;
        Object params[] = {customer, ssoId};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        customer.setId(obj.longValue());
        CustomerHashFacade.put(customer, ssoId);
        return obj.intValue();
    }

    public static int create1(Customer customer, String ssoId, String username) throws Exception {
        String methodName = "CustomerService_create1";
        String soapAction = "CustomerService_create1";

        Class returnType = Integer.class;
        Object params[] = {customer, ssoId, username};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        customer.setId(obj.longValue());
        CustomerHashFacade.put(customer, ssoId);
        return obj.intValue();
    }

    public static void addCustomerToGoogleUser(int customerId, String googleUser, String ssoId) throws Exception {
        String methodName = "CustomerServer_addCustomerToGoogleUser";
        String soapAction = "CustomerServer_addCustomerToGoogleUser";
        Object params[] = {customerId, googleUser, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
    }

    public static void update(Customer customer, String ssoId) throws Exception {
        String methodName = "CustomerService_update";
        String soapAction = "CustomerService_update";

        Object params[] = {customer, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        CustomerHashFacade.put(customer, ssoId);
    }

    public static Customer get(int id, String ssoId) throws Exception {
        String methodName = "CustomerService_get";
        String soapAction = "CustomerService_get";

        Class returnType = Customer.class;
        Object params[] = {Integer.valueOf(id), ssoId};

        Customer obj = CustomerHashFacade.get(id, ssoId);
        if(obj==null) {
            obj = (Customer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        }
        return obj;
    }

    public static List<Customer> getList(String ssoId) throws Exception {
        String methodName = "CustomerService_getList";
        String soapAction = "CustomerService_getList";

        Class returnType = List.class;
        Class returnType1 = Customer.class;
        Object params[] = {ssoId};

        List<Customer> obj = CustomerHashFacade.getList(ssoId);
        if(obj==null) {
            obj = (List<Customer>) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, returnType1);
            CustomerHashFacade.addList(obj, ssoId);
        }
        return obj;
    }

    public static void remove(int id, String ssoId) throws Exception {
        String methodName = "CustomerService_remove";
        String soapAction = "CustomerService_remove";

        Object params[] = {ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        CustomerHashFacade.remove(id, ssoId);
    }
}
